package xyz.xtt.user.mq;

import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import xyz.xtt.user.service.ThirdService;
import xyz.xtt.user.vo.user.TongTongUserInfo;

/**
 * @author huqibo
 *
 */
@RefreshScope
@Slf4j
@Component
@RocketMQMessageListener(topic = "${rocketmq.consumer.usersync}", consumerGroup = "${rocketmq.consumer.group.usersync}")
public class UserRegisterConsumer implements RocketMQListener<String> {
	@Autowired
	private ThirdService thirdService;
	@Value("${rocketmq.consumer.usersync}")
	private String topic;

	@Override
	public void onMessage(String message) {
		log.info("UserRegisterConsumer receive message topic:{}, msg:{}", topic, message);
		TongTongUserInfo userInfo = JSONUtil.toBean(message, TongTongUserInfo.class);
		thirdService.syncUser(userInfo);
	}

}
